Dhaga ne ShonaScript
Apa ndopauchaona kunyora code
kwave kuita kunge magic
, saka gadzirira.
#
Box ne BhataniTave kudzokera ku box
ne bhatani
.
Taona kuti bhatani ne box zvinogadzirwa sei kumashure, asi ma bhatani edu anga asingashande nekuti haana kupihwa zvekuita zvacho kana munhu achinge amabaya.
Taakuda kuumba zvinhu izvi:
box
regreen
bhatani
rekutanga rekuti munhu akabaya,box
rinochinja kuitared
bhatani
rechi 2 rekuti munhu akabaya,box
rinochinja kuitagreen
Tikuda kuedza kuteedzera zvinoitatraffic light
muroad richimisa mota
Kuti Uzoudza ShonaScript zvekuita nema box
, kana munhu achinge abaya ma bhatani
unofana kupa zvinhu zvese izvi mazita kunge mavariables
.
Panguva ino unotarisirwa kunge uchiziva kuti mavariables
anobvumidzwa akaita sei sezvakatsanangurwa mu ShonaScript. Saka tichapa mazita aya:
box
-boxOne
bhatani
rekutanga -btOne
bhatani
rechi 2 -btTwo
zita racho rinongonyorwa pamberi pe chinhu chacho sokuti:
box boxOne:;
Tichabva taudza shonascript kuti kana munhu abaya bhatani rekutanga btOne
, chinja color
ye boxOne
kuita green
. Pakubayawo bhatani btTwo
, chinja color
ye boxOne
kuita red
Unoshandisa shonascript mudhaga seizvi:
shonascript{
}
Izvi ndizvo zvinoratidza kuti waakuisa shonascript ichashanda ne Dhaga
iri muma brackets
ayo.
chii chikuitika apa
- Tagadzira
box
rinekf-10
,kr-10
, tobva tabvisa makona nakn-10
- Tagadzira mabhatani 2 re green richazoita kuti box richinje kuita green, nere red richazoita kuti
box
richinje kuitared
- Tanyora ShonaScript inoita kuti kana munhu abaya
btOne
,box
riite green, asi kana abayawobtTwo
,box
riitered
ShonaScript yashanda apa
ShonaScript yatiri kushandisa apa ndiyo yekare, asi yakawedzerwa zvimwe zvinhu zvinoita kuti ugone kuishandisa ne Dhaga
.
Ngatitarise ShonaScript yatashandisa apa.
pakubaya btOne {
}
Apa tinenge tichiudza ShonaScript kuti pakubayiwa kwa btOne
, ita izvi zviri muma brackets
pakubaya btOne { pa boxOne chinja c kuita "red"}
Apa tikudza ShonaScript kuti kana munhu abaya btOne
, enda pana boxOne
, obva wachinja c
, apa c
ndiyo color
iye ye box
, kuita red
.
Ukasaisa ma quotes
pana red
, ShonaScript ichafunga kuti red wacho ivariable
, saka ichaedza kutsvaga kuti variable
yacho yambogadzirwa here mu shonascript. Kana variable iyi isina kumbogadzirwa, unoudzwa kuti paita problem
.
#
Zvimwe Zvaunogona kuchinjaPamusoro apa tangochinja color
tichishandisa c
Unogona kuchinjawo izvi:
Chekuchinja | Muenzaniso |
---|---|
c - color | pa boxOne chinja c kuita "red" |
ms - mashoko | pa boxOne chinja ms kuita "Zita rako" |
kn - kona | pa boxOne chinja kn kuita 4 |
kf - kufara(width) | pa boxOne chinja kf kuita 2 |
kr - kureba(length) | pa boxOne chinja kr kuita 3 |
ms-c - color yemashoko | pa boxOne chinja ms-c kuita "purple" |
v - viga box | pa boxOne chinja v kuita "hongu" kana kuti pa boxOne chinja v kuita "kwete" |
Chine basa apa kuziva zvaukuda kuchinja pa box
rako, hazvireve kuti unofana kuchinja zvinhu zvese zvepa box
#
Kutora zvinhu zveboxTaona kuti unogona kuchinja zvinhu zvepa box kana zviri mukati macho uchishandisa
pa boxOne chinja c kuita "red"
Unogona kunge uchida kuona kuti c
wacho wepa box
ndiani. Apa unenge uchiedza kumutora c
iyeye woita zvaunoda naye, seizvi
pakubaya btOne{ x = pa boxOne tora c nyora(x)}
Apa tatora c
pa boxOne
tichishandisa pa boxOne tora c
, tobva tagadzira variable
yacho yezvatinowana ipapo.
Pazasi pacho tazotuma shonascript kuti ichinyora variable iyi
chii chikutika apa
- Tabvisa
btTwo
kubva muDhaga
- Mu ShonaScript, tashandisa
pa boxOne tora c
kuti titorecolor
, tobva tagadziravariable
inonzix
ye color iyoyo - Tashandisa
nyora(x)
kunyora variable x yagadzirwa paline 11
- Nyora anoburitsa
box
rakanyorwa zvinhu zvacho zvawatumaShonaScript
kuti ikunyorere, saka apa pabuda oakanzigreen
, zvechokwadiwo,boxOne
wedu tamupac-green
muDhaga
#
Kutora zviri mu boxUnokwanisa kutora mashoko arimubox
rinonzi boxOne
uchishandisa ms
seizvi:
pa boxOne tora ms
Kana mubox muinewo nhamba chete pasina chimwe chinhu, unoitora nhamba iyoyo uchishandisa nm
seizvi:
pa boxOne tora nm
Musiyano uri pakati pemashoko nenhamba ndewekuti mashoko haakwanise kusanganiswa sezvinoita ma nhamba sokuti 1+1
inokupa 2
Ukaedza kusanganisa mashoko sokuti
"panashe" + "muriro"
panobuda panashe muriro
, mashoko aya haana kusanganisw, asi abatanidzwa, saka ndiwo musiyano uripo
Saka izvi zvinoreva kuti ukaenda mu shonascript ukanyora
"2"+"2"
panobuda 22
, hazvisi kureva maths
yekuti kuti 2+2
inoburitsa 22
, asi zvikureva kuti mashoko ekuti "2" na "2" vabatanidzwa kuita 22
Izvi zvakakosha kunzwisisa nekuti kana uine nhamba mu box
sokuti
box boxOne:23;
obva waudza ShonaScript
kuti tora mashoko arimu box uchishandisa
x = pa boxOne tora ms
ShonaScript inokupa x ari "23" apa, zvichireva kuti ukazoedza kuda kusanganisa x uye ne imwe nhamba sokuti 20 ShonaScript inotarisa zvinhu izvi sokuti
"23"+20
Nekuti ukuda kuedza kusanganisa mashoko ne nhamba, ShonaScript ichangobatanidza zvinhu izvi kuita 23 20
nekuti haukwanise kusanganisa mashoko
ne nhamba
Chitarisa zvikutika apa
chii chikuitika apa
- Tatora mashoko arimu
boxOne
tichishandisams
.- Nhamba 23 irimo mu
boxOne
ichaonekwa semashoko kuti "23"
- Nhamba 23 irimo mu
- Taedza kusanganisa mashoko aya ne nhamba 20, tobva tagadzira
variable
inonziy
, yatichazonyora kuti tione kuti zvii zvaitika - Pabuda
23 20
, saka apa hapana kusanganiswa ma mashoko ne nhamba, asi zvabatanidzwa
chii chikuitika apa
- Tatora nhamba irimu
boxOne
tichishandisanm
. - Tasanganisa nhamba iyi neimwe nhamba, izvi zvnosanganisika
- Panobuda 43 nekuti ndiyo 20 + 23
#
Chinonzi Website ne Web ApplicationKumashure uku tanga tichinyanya kutaura kuti website
.
Apa nekuti taakushandisa ma bhatani tichiita kuti munhu abaye achichinja zvinhu, tinenge tichigadzira inonzi web application
.
Musiyano uripo pakati pe website
ne web application
ndewekuti website
inonyanya kunge iri yekuverenga zvinhu pasina zvakawanda wanda zvekubaya kana kuchinja, asi web application
inoita mabhatani akawanda uye pane kuchinja chinja kunenge kuchiitika ipapo.
Kana ukaenda pa google wotanga kushandisa application yeShonaScript
, unenge uchishandisa web application
ipapo.
Whatsapp haisi web application
, itongori application
yemuphone chaiyo.
Makhambani anoshandisa ma website
kuti vaudze vanhu basa ravanoita uye kuti kuratidza ma picture
ebasa ravo.
Web application
yakaoma kugadzira kupfuura website
.
Ukaona uchinyora code
ye Dhaga
pasina ShonaScript
, unobva waziva kuti ukugadzira website
. Ukazotanga kunyora ShonaScript
mu Dhaga
, unobva waziva kuti ukugadzira web application
Zvekuita
Gadzira web application
ine zvinhu izvi:
- Box rine:
- zita rekuti
boxOne
kf-10
kr-10
- mashoko ari pakati
- mashoko akakura
ms-sz-4
- mashoko akakora
ms-uk-4
color
yebox
yaunodacolor
yemashoko yaunoda
- zita rekuti
- Bhatani rine:
- icon ye yekubvisa
minus
โ - zita rekuti btOne
- icon ye yekubvisa
- Bhatani rine
- icon yekusanganisa
plus
โ๏ธ - zita rekuti btTwo
- icon yekusanganisa
- ShonaScript:
- pakubaya btOne
Ukabaya bhatani rine -
, unofana kuona nhamba iri mu boxOne
ichiita idiki. Ukabayawo +
inofana kuita ihombe
#
Kuisa mashoko kubva mulistNgatimboti une list
mu shonascript
, ukuda kuona zvinhu izvi zviri mulist pa application
yako, unongoshandisa ms
zvekare kuita izvi.
box boxOne:;
shonascript{vanhu = ["Tadiwa", "Rumbi", "Kudzi"];pa boxOne chinja ms kuita vanhu}
chii chikuitika apa
- Tagadzira
box
rinonziboxOne
- Tashandisa shonascript kuichinja zviri mu
box
kuita zvinhu zvese zviri mulist
- zvinhu zviri mulist zvinorongwa zvichidzika sezvikuoneka pa
picture
iyi
- zvinhu zviri mulist zvinorongwa zvichidzika sezvikuoneka pa
#
Teerera mhinduroUnoshandisa teerera mhinduro kana uchida kuti munhu anyore mashoko mu application yako.
Kuti uzotore zvinhu zvinenge zvanyorwa nemunhu mubox
re teerera munduro
unongohsnadisa tora ms
sezvatanga tichiita pa box
.
Zvekuita
Tikuda kugadzira zvinhu izvi:
- box rine:
kf-10
kr-10
color
chero yatinofarira- zita rekuti
boxOne
- teerera mhinduro
tm
ane:
kf-10
color
chero yatinofarira- zita rekuti
tmOne
- bhatani rine:
- mashoko ekuti
chinja color
kf-3
kn-2
- zita rekuti
btOne
- shonascript
- pakubaya
btOne
- pa tmOne tora ms
- gadzira variable ye
pa tmOne tora ms
- pa boxOne chinja c kuita color inenge yanyorwa nemunhu mu
tmOne
Kana ukanyora color
mu tmOne
umo wobaya bhatani, uchaona kuti boxOne
achachinja color.
Unogona kunyora ma color anotanga na #
aye arikumberi kwebhuku zvekare.
Zvekuita
Taakudzokera ku topic ye ma list
yeku shonascript. Kuti unzwisise list
zvekare, pakatsanangurwa kuti iwewe kana uchinge uchida kunotenga zvinhu, wobva wanyora pasi zvinhu zvacho, unenge uchinyora list
.
Tikuda kugadzira aplication
ine list
ratichange tichiisa zvinhu zvatiri kuda kunotenga pamusika.
Chakakosha kuziva kuti tichashandisa chii kugadzira application iyi. Izvi ndizvo zvatichashandisa:
- box rekutanga rine:
kf-10
kr-2
- mashoko ekuti Shopping List, kana kuti zvimwe zvaunoda kunyora
- unogona kuchinja color yemashoko ne box racho kuita ma
color
aunofarira - Hatisi kuda kuchinja chinhu ne shonascript pa box iri, saka usaripe zita
- box rechi 2 rine:
- zita rekuti
bxOne
kf-10
kr-10
- color yaunoda, tichatsvaga color yakarerekera ku
white
- teerera mhinduro ine:
- zita rekuti
tmOne
- color yakarerekera ku white
kf-10
kr-10
- bhatani rine:
- zita rekuti
btOne
- color yaunoda
- icon ye kusanganisa (
plus
)โ๏ธ kf-2
kf-2
kn-10
- ShonaScript:
- Munhu achatanga anyora zvaari kuda kunotenga pamusika
- gadzira list rako, asi usaise chinhu -
zvinhu = []
- pakubaya
btOne
- pa tmOne tora ms anyorwa ne munhu
- gadzira variable yemashoko aya -
x = pa tmOne tora ms
- chiisa variable iyi mu -
zvinhu.isa(x)
- chinja mashoko arimu
boxOne
kuita zvhinhu -pa boxOne chinja ms kuita zvinhu
Ukanyora zvinhu mu tmOne
wobaya bhatani btOne
, unoona kuti zvawanyora zvave mu box.
Izvi zvinotika nekuti list
rako rezvinhu rawagadzira rawedzerwa nechinhu chawanyora mu tmOne
.
Zvekuita
Chiisa rimwe bhatani rekuti kana munhu anyora mu tmOne
, anobva abvisa zvaanyora izvozvo mulist
re zvinhu riye.
#
Kugadzira box ne ShonaScriptNgatimboti ukuda kugadzira mabox
akafanana ari 10, unogona kutongogadzira mabox aya ari 10 mu dhaga seizvi:
box:;box:;box:;box:;box:;box:;box:;box:;box:;box:;
Izvi zvinoreva kuti kana ichida kugadzira 1000 mabox
akafanana, unenge waakufana kunyora maline akawandisa e code ye Dhaga
.
Ukaenda mu whatsapp, unoona kuti pamunhu wega wega waunotaura naye, panenge paine picture
, zita
, ne message yapedzisira kutumirwa kana kuti kusvika.
Aya angori ma box
akafanana asi obva azongosiyana zviri mukati mawo, zvinoti: picture
,zita
ne message
.
Ngatimboti ukuda kugadzira mabox 5 ane mazita aya "Taku", "Sandra","Ruvimbo", "Tatenda", "Danai"
. Tichatarisa nzira 2 dzaunogona kushandisa kuti zviitike
#
1. Kushandisa Dhaga chetechii chikuitika apa
- Taumba ma
box
5 aya tichiumbabox
rimwe ne rimwe neDhaga
- Kana tchida kuumba ma box 1000, zvinoreva kuti tinenge tichifana kutonyora ma line e
Dhaga
anopfuura 1000, maline aya akawandisa uye tinenge tichizvipa basa rakawanda kana tikada kushandisa nizra iyi
#
2. Kushandisa ShonaScript ne Dhagachii chikutika apa
- Taumba
box
rekubata nzvimbo muDhaga
rinonziboxTwo
.box
rekubata nzvimbo rakangofanana ne hembe dzaunoona dzakapfekedzwa zvidhori mu shop ye hembe.- Hembe idzi dzinenge dziri dzekuti vanhu vaone kuti dzinobuda sei kana dzapfekwa, asi panozoita dzimwe dzakangofana dzinenge dzichitengeswa.
- Mu
boxTwo
taisavariable
inonzizita-ss
, izvi zvinoreva kuti variable iyi inonzizita
, asi ichabva kuShonaScript
.
- Taumba box rekutanga rinonzi
boxOne
, umu ndimo matichazoisa mabox
atichaumba tichishandisaboxTwo
muShonaScript.
Mu ShonaScript:
- Tagadzira
list
revanhu["Taku", "Sandra","Ruvimbo", "Tatenda", "Danai"]
- Tapinda mu
list
tichishandisapane munhu nu vanhu
- Tichinge tapinda mu list tiri pane munhu wekutanga, Taku, tichaita izvi:
- Tichatora
boxTwo
rekubata nzvimbo riye togadziravariable
~x = pa boxTwo tora box
- Tichinge tave naro, tichachinja variable iya inonzi zita yoita munhu arimu
list
tichitiss-zita-x
, izvi zvinoreva kuti ShonaScript ngaichitora variable iya inonzizita
yepax
,x
ndiroboxTwo
ratagadzira pamusoro. - Saka kana tiri pana
Taku
, tinenge tave nebox
rine mashoko ekuti Taku mukati. - Kuti tizoisa box iri pa
website
, unenge waakufana kuriisa mukati merimwebox
, apaboxOne
ndiro ratagadzira richapinda mabox
arikubva kuShonaScript x
avebox
rine mashoko ekuti Taku mukati, kuti tiriise mukati me rimwe box riri muDhaga
, tinenge tave kushandisapa boxOne wedzera box ne x
- Apa hatisikuchinja zviri mu
boxOne
, asi kuti tiri kuda kuwedzera pane zviri mubox imomo- Chimboedza kufunga kuti chii chinoitika kana ukshandisa
pa boxOne chinja box kuita x
- Chimboedza kufunga kuti chii chinoitika kana ukshandisa
- Tikabva pana Taku taakuenda pana Sandra, tichatora
boxTwo
riya rekubata nzvimbo zvekare, tongoita sezvataita pekutanga, zvichingodaro - Uchaoona kuti ma
box
5 anogadzirika.
- Tichatora
Zvekuita
- Enda mu
list
revanhu mu ShonaScript, chiwedzera mazita evanhu nemamwe aunoda - Chitarisa kuti panobuda ma
box
mangani
Apa taona kuti mashoko arimubox ragadzirwa ne ShonaScript anochinjwa sei, unogonawo kuchinja mamiriro ebox uchishandisa nzira iyi.
Ngatimboti une list rema color
, ["red","yellow","blue","purple","black"]
, unogona kugadzira mabox ane ma color aya uchishandisa ShonaScript sezvatongoita pamusoro apa.
chii chikuitika apa
- Tine
boxTwo
, asicolor
yebox
iri tikuda kuti ibve ku ShonaScript, saka taisac-ss
, pane kutic-red
. Izvi zvinoreva kutic
acabva kuShonaScript. Mu ShonaScript: - Tazoti
ss-c-x = color
zvichireva kuti ShonaScript ngaichichinjac
uye wepabox
ratatorax
kuitacolor
irikubva mulist
.
Kushandisa bhegi
- Unogona kuda kuchinja
color
zvese nemashoko arimukati, sokuti ukuda kuti box rakanyorwa kuti Taku, riite red, ozoda kutibox
rakanyorwa kuti Sandra riitepurple
. - Izvi zvinokwanisika uchishandisa chinonzi
bhegi
mu ShonaScript
#
Chii chinonzi bhegi?Kuti unzwisise chinonzi bhegi
mu ShonaScript, ngatimboti iwewe une list remazita ezvinhu seizvi:
zvinhu = ["madomasi", "zumbani","mango"]
Dambudziko riripo pa list
rakadai nderekuti ungorine nemazita ezvinhu zvaukuda kunotenga pamusika chete pasina zvimwe.
Ngatimboti iwewe ukuda kuti list
rako riratidze mari inokwana kutenga chinhu chimwe nechimwe chiri mu list rako sokuti:
madomasi anoita $3zumbani rinoita $1mango dzinoita $2
Kana ukada kushandisa list
remashoko, zvinonetsa kuti uronge zvinhu izvi nemari yazvo. Apa ndipo panoshanda bhegi
.
Bhegi
ririkutaurwa nezvaro apa ndiwo mabhegi
aunoziva. Chine basa kuziva apa ndechekuti bhegi
rine homwe
.
Bhegi
rinogona kuita homwe
dzakasiyana siyana, dzepakati, dzepaside, dzekunze zvichingodaro.
Isusu kana tichifunga nezvebhegi, tiri kuda kupa homwe dzebhegi mazita akasiyana siyana sokuti tichapa imwe homwe dzebhegi
redu mazita ekuti zita
ne mari
.
Muhomwe inonzi zita, tichaisa zita rechinhu chikuda kunotengwa chacho, tozoisa mari ichashandiswa mu homwe inonzi mari
.
Unoita izvi muShonaScript sokudai:
{"zita": "madomasi", "mari": 3}
Uku ndiko kutogadzira bhegi rine homwe yekutanga inonzi zita
ine zita rechinhu chikuda kutengwa, yozoita imwe homwe inonzi mari
ine nhamba yamari yacho ichashandiswa.
Kana waakuda kuona zviri muhomwe inonzi zita
, unotanga wagadzira variable ye bhegi iri seizvi:
x = {"zita": "madomasi", "mari": 3}
Apa tiri kuti x
ndiro bhegi redu ratagadzira, tinovhura homwe inonzi zita seizvi:
x["zita"]
Kuti tione kuti chiinobuda kana tavhura homwe iyi, tinenge tave kugadzira variable
yatinozonyora kuti tione kuti zvii zvikuitika.
Taakudzokera ku ShonaScript
chii chikuitika apa
- Apa tadzokera ku ShonaScript
- baya
bhatani
riri pazasi pe screen kuright
, woenda pakanziShonaScript
- baya
- Tagadzira bhegi rinonzi
x
rine homwe inonzizita
ine"madomasi"
, ne imwe homwe inonzimari
ine3
- Tavhura homwe inonzi
zita
, tobva tagadziravariable
yezvinhu izvi inonziy
- Tavhura homwe inonzi
mari
, tobva tagadziravariable
yezvinhu izvi inonziz
- Tanyora ma
variables
aya kuti tione kuti zvii zvinobuday
aburitsa"madomasi"
ndiyo homwe yezita yatavhura nex["zita"]
z
aburitsa3
ndiyo homwe yezita yatavhura nex["mari"]
Saka pane kuti uve ne list
remashoko, unogona kuva ne list
remabhegi
sokuti:
zvinhu = [ {"zita": "madomasi", "mari": 3}, {"zita": "zumbani", "mari":1}, {"zita": "mango", "mari": 2}]
Kana uine list rakadai, unogona kupinda mariri uchishandisa pane chinhu mu zvinhu
sokuti:
pane chinhu mu zvinhu{
}
Apa chine basa kunzwisisa ndechekuti kana wapinda mu list iri ne variable
inonzi chinhu
, variable
ichange ichichinja kuita bhegi
kusvika wabuda.
Kana uri pane chinhu chekutanga, chinhu
anoita chinhu = {"zita": "madomasi", "mari": 3}
, saka kana waakuda kuona kuti pabude zvinhu zviri muhomwe inonzi "zita"
, unenge waakuvhura homwe seizvi chinhu["zita"]
.
chii chikuitika apa
- Tagadzira list rezvinhu zvatikuda kunotenga
- Tapinda mu list ne
variable
inzonzi chinhu -pane chinhu mu zvinhu
- Tanyora
chinhu
pa line 7 kuti tione kuti panobuda chii- apa pabuda
bhegi
rine homwe ne zviri muhomwe macho sokuti{"zita": "madomasi", "mari": 3}
- apa pabuda
- Tavhura homwe inonzi
zita
tichishandisachinhu["zita"]
, tobva tagadzira variable inonzix
yatazonyora paline 9
Taakuda kudzokera ku Dhaga
tonoshandisa list re bhegi
kuchinja mashoko ne color
Zvekuita
- Wakapihwa list rema bhegi rakadai:
zvinhu = [ {"zita": "Taku", "color": "red"}, {"zita": "Sandra", "color": "blue"}, {"zita": "Ruvimbo", "color": "green"}, ]
- Gadzira
box
rinonziboxOne
richapinda mabox
achabva kuShonaScript - Gadzira rimwe
box
pazasi rinonziboxTwo
mudhaga, rinec-ss
, ne mashoko mukati ekutizita-ss
zvichabva ku ShonaScript sezvatamboita kumashure Mu ShonaScript - gadzira
variable
inonzix
yoitaboxTwo
seizvi:
x = pa boxTwo tora box
- pinda mu list remabhegi,
zvinhu
, nevariable inonzichinhu
seizvi
pane chinhu mu zvinhu{
}
- vhura homwe inonzi zita, ochinja
variable
iya yabva kuDhaga
inzonzizita-ss
yepabox
ratatora kuita
ss-zita-x = chinhu["zita"]
- Ita izvi kuchinja color
ss-c-x = chinhu["color"]
- chiwedzera
box
iri muboxOne